$('#main_container').ready(function(){
    $('#uc_catamenu ').show();
    $('.dir_name_row').css('margin-left',(window_width+50)+'px');
    $('.dir1_row').show();
    var sidemenu_width = window_width*0.7;
    var sidemenu_backwidth = window_width*0.7+30;
    $('.uc_catamenu ').width(sidemenu_width+"px");
    $('.uc_catamenu ').css('right','-'+sidemenu_backwidth+"px");
    //$('.dir1_row').addClass('transform_dir1_row');
    var dir_name_row_now_duration = 400;
    $('.dir_name_row').each(function(){
        $(this).animate({'margin-left':'0','opacity':1},dir_name_row_now_duration+300);
        dir_name_row_now_duration+=200;
    });

    $('#sidemenu_filter').click(function(){
        $("#uc_catamenu").animate({right:"-"+sidemenu_backwidth+"px"});
        $('#sidemenu_filter').hide();
    });

    //客户端宽度-
    preimg_box_row_width = $('#container').width()-40;
    //获取预览图单个box宽度
    preimg_box_width = Math.ceil(preimg_box_row_width/3.005);
    video_box_width = Math.ceil(preimg_box_row_width/2.005);
    $('#prebox_width').val(preimg_box_width);
    $('#video_width').val(video_box_width);

    //还原用户记录动作
    if(window.sessionStorage && sessionStorage[alias+'_action']){
        //rememberBysS(alias);
    }

    //当前一级目录的数量
    var dir1_count = $('#dir1_content').find('.dir1_row').length;
    if(parseInt(dir1_count)==1){
        //直接跳转二级目录
        $('#dir1_content').find('.dir1_row').eq(0).click();
    }



});


//点击一级目录
function click_dir1row(did){
    //一级目录id
    if(did){
        $('#d1id').val(did);
        var d1id = did;
    }else{
        var d1id = $('#d1id').val();
    }
    //一级目录提交密码
    var d1pwd = $('#i_d1Password').val();
    if(window.sessionStorage && sessionStorage['dir2Of_'+d1id]){
        var dir2Info = sessionStorage['dir2Of_'+d1id];
        $('#uc_sysmenu').html('');
        $('#uc_sysmenu').append(dir2Info);
        //$('#dir1_container').hide();
        //记录动作
        sessionStorage[alias+'_action'] ="2%"+'dir2Of_'+d1id;
        //$('#dir2_container').show();
        $("#uc_catamenu").animate({right:"0px"});
        $("#sidemenu_filter").show();
    }
    else if($.cookie('dir2Of_'+d1id)){
        var dir2Info =$.cookie('dir2Of_'+d1id);
        $('#uc_sysmenu').html('');
        $('#uc_sysmenu').append(dir2Info);;
        //$('#dir1_container').hide();
        //$('#dir2_container').show();
        $("#uc_catamenu").animate({right:"0px"});
        $("#sidemenu_filter").show();
    }else{
        //获取该一级目录下的二级目录信息
        $.ajax({
            type: "POST",
            url: mw_site_url+"/dir/ajax",
            async: true,
            data: "op=1&did="+d1id+"&d1pwd="+d1pwd,
            dataType:"json",
            cache:false,
            beforeSend:function(){
                $('#dir2_content').html("<section class='loading'></section>");
                $('#submit_d1Password').attr('disabled',true);
            },
            success: function(data){
                $('#dir2_content').find('.loading').remove();
                if(parseInt(data['error'])==1){
                    alert(data['error_msg']);
                    return false;
                }
                else if(parseInt(data['error'])==2){
                    //该目录有加密且没有解密记录,提示需要解锁
                    $('#submit_d1Password').removeAttr('disabled');

                    $('#d1ul_block').modal('show');
                    return false;
                }else if(parseInt(data['error'])==3){
                    //提交的解锁密码错误
                    $('#submit_d1Password').removeAttr('disabled');
                    $('#i_d1Password').val('');
                    alert(data['error_msg']);
                    return false;
                }else{
                    //获取二级目录成功
                    var dir2Info = data['data'];
                    var dir2_html = "";
                    $('#uc_sysmenu').html('');

                    for(var i=0;i<dir2Info.length;i++){
                        $('#uc_sysmenu').append(dir2Info[i]);
                        dir2_html+=dir2Info[i];
                    }
                    if(window.sessionStorage){
                        var did = $('#d1id').val();
                        var alias = $('#alias').val();
                        sessionStorage['dir2Of_'+did]=dir2_html;
                        //记录动作
                        sessionStorage[alias+'_action'] ="2%"+'dir2Of_'+did;
                    }else{
                        $.cookie("dir2Of_"+did,dir2_html);
                    }
                    $('#d1ul_block').modal('hide');
                    $('#submit_d1Password').removeAttr('disabled');
                    //隐藏一级目录，显示二级目录
                    $("#uc_catamenu").animate({right:"0px"});
                    $("#sidemenu_filter").show();
                    /*$('#dir1_container').hide();
                    $('#dir2_container').show();*/
                }
            }
        });
    }
    /*//当前二级目录的数量
    var dir2_count = $('#dir2_content').find('.dir2_info').length;
    if(parseInt(dir2_count)==1){
        //直接跳转第三级目录
        $('#dir2_content').find('.dir2_info').eq(0).click();
    }*/

}

//点击返回一级目录
function click_dir2head(){
    //隐藏二级目录，显示一级目录
    $('#dir2_container').hide();
    $('#dir1_container').show();
    sessionStorage[alias+'_action'] ="1%sb";
}

//点击二级目录
function click_dir2row(d2id,dir2Name,d1id){
    $('#prehead_label').html(dir2Name);
    $('#d1id').val(d1id);
    $('#dir2Name').val(dir2Name);
    if(window.sessionStorage && sessionStorage['preImgsOf_'+d2id]){
        var preview_content = sessionStorage['preImgsOf_'+d2id];
        $('#preview_content').html('');
        $('#preview_content').append(preview_content);
        //设置所有预览图box高度等于宽度
        var prebox_witdh = $('#prebox_width').val();
        $('.preimg_box').css('width',prebox_witdh);
        $('.preimg_box').css('height',prebox_witdh);
        $('.preimg_box img').css('height',prebox_witdh);
        $('#dir1_container').hide();
        $('#dir2_container').hide();
        $('#preview_container').show();
        //懒加载
        $('#preview_content img').lazyload(function(){
            effect : "fadeIn"
        });
        //记录用户动作
        sessionStorage[alias+'_action'] ="3%dir2Of_"+d1id+"%preImgsOf_"+d2id+"%"+dir2Name;
        $('#preview_container').find('.dir_head').attr('onclick','click_preimghead("'+d1id+'");');
    }
    else if($.cookie('preImgsOf_'+d2id)){
        var preview_content =$.cookie('preImgsOf_'+d2id);
        $('#preview_content').html('');
        $('#preview_content').append(preview_content);
        //设置所有预览图box高度等于宽度
        var prebox_witdh = $('#prebox_width').val();
        $('.preimg_box').css('width',prebox_witdh);
        $('.preimg_box').css('height',prebox_witdh);
        $('.preimg_box img').css('height',prebox_witdh);
        $('#dir1_container').hide();
        $('#dir2_container').hide();
        $('#preview_container').show();
        //懒加载
        $('#preview_content img').lazyload(function(){
            effect : "fadeIn"
        });
        $('#preview_container').find('.dir_head').attr('onclick','click_preimghead("'+d1id+'");');
    }else{
        //获取二级目录下的图片
        $.ajax({
            type: "POST",
            url: mw_site_url+"/dir/ajax",
            async: true,
            data: "op=2&d2id="+d2id+"&alias="+alias,
            dataType:"json",
            cache:false,
            beforeSend:function(){
                //隐藏一级目录，显示二级目录
                $('#preview_content').html("<section class='loading'></section>");
                $('#dir1_container').hide();
                $('#dir2_container').hide();
                $('#preview_container').show();
            },
            success: function(data){
                $('#preview_content').find('.loading').remove();
                if(parseInt(data['error'])==1){
                    alert(data['error_msg']);
                }else{
                    var preImgs = data['data'];
                    var preimg_html = "";
                    if(parseInt(preImgs.length)>0){
                        for(var i=0;i<preImgs.length;i++){
                            $('#preview_content').append(preImgs[i]);
                            preimg_html+=preImgs[i];
                        }
                    }else{
                        $('#preview_content').html("<section style='text-align: center;' >暂无图片信息...</section>");
                        preimg_html = "<section style='text-align: center;' >暂无图片信息...</section>";
                    }
                    if(window.sessionStorage){
                        sessionStorage['preImgsOf_'+d2id]=preimg_html;
                        //记录用户动作
                        var d1id =  $('#d1id').val();
                        var dir2Name =  $('#dir2Name').val();
                        var alias =  $('#alias').val();
                        sessionStorage[alias+'_action'] ="3%dir2Of_"+d1id+"%preImgsOf_"+d2id+"%"+dir2Name;
                        $('#preview_container').find('.dir_head').attr('onclick','click_preimghead("'+d1id+'");');
                    }else{
                        $.cookie("preImgsOf_"+d2id,preimg_html);
                    }
                    $('#preview_content').html('');
                    $('#preview_content').append(preimg_html);
                    //设置所有预览图box高度等于宽度
                    var prebox_witdh = $('#prebox_width').val();
                    $('.preimg_box').css('height',prebox_witdh+'px');
                    $('.preimg_box').css('width',prebox_witdh+'px');
                    $('.preimg_box img').css('height',prebox_witdh+'px');
                    $('#dir1_container').hide();
                    $('#dir2_container').hide();
                    $('#preview_container').show();
                    $('#preview_content img').lazyload(function(){
                        effect : "fadeIn"
                    });

                }
            }
        });
        $.ajax({
            type: "POST",
            url: app_url+"app.php/custom/clickdir ",
            async: true,
            data: "uuid="+d2id,
            dataType:"json",
            cache:false,
            success: function(data){

            }
        });
    }
}

//点击返回二级目录
function click_preimghead(d1id){
    $('#preview_container').hide();
    $('#dir2_container').show();
    //记录动作
    sessionStorage[alias+'_action'] ="2%"+'dir2Of_'+d1id;
    //当前二级目录的数量
    var dir2_count = $('#dir2_content').find('.dir2_info').length;
    if(parseInt(dir2_count)==1){
        //直接跳转第三级目录
        $('#dir2_container').find('.dir_head').eq(0).click();
    }
}

//根据sessionStorage展示用户记录操作
function rememberBysS(alias){
    var action_arr = sessionStorage[alias+'_action'].split('%');
    var action = parseInt(action_arr[0]);
    switch(action){
        case 2:
            //获取二级目录存储数据
            var dir2sS = action_arr[1];
            var dir2Info = sessionStorage[dir2sS];
            $('#uc_sysmenu').html('');
            $('#uc_sysmenu').append(dir2Info);;
            /*$('#dir1_container').hide();
            $('#dir2_container').show();*/
            break;
        case 3:
            //获取三级目录存储数据
            var dir2sS = action_arr[1];
            var preImgsS = action_arr[2];
            var dir2Name = action_arr[3];
            $('#prehead_label').html(dir2Name);
            $('#uc_sysmenu').html('');
            var dir2Info = sessionStorage[dir2sS];
            //加载二级目录
            $('#uc_sysmenu').append(dir2Info);
            var preview_content = sessionStorage[preImgsS];
            $('#preview_content').html('');
            var d1id = dir2sS.split('_')[1];
            //设置预览图标题
            $('#preview_container').find('.dir_head').attr('onclick','click_preimghead("'+d1id+'");');
            //加载预览图
            $('#preview_content').append(preview_content);
            //调整预览图大小
            var prebox_witdh = $('#prebox_width').val();
            $('.preimg_box').css('width',prebox_witdh);
            $('.preimg_box').css('height',prebox_witdh);
            $('.preimg_box img').css('height',prebox_witdh);
            $('#dir1_container').hide();
            $('#dir2_container').hide();
            $('#preview_container').show();
            //懒加载
            $('#preview_content img').lazyload(function(){
                effect : "fadeIn"
            });
            break;
        case 4:
            var videosS = "video_"+alias;
            var video_html = sessionStorage[videosS];
            $('#video_content').html('');
            $('#video_content').append(video_html);
            //设置所有企业视频box高度等于宽度
            var video_witdh = $('#video_width').val();
            $('.video_box').css('width',video_witdh);
            $('.video_box').css('height',parseInt(video_witdh)+45);
            $('.video_box img').css('height',video_witdh);
            $('#dir1_container').hide();
            $('#video_container').show();
        default :
            break;
    }
}

function click_videorow(){
    //
    var alias = $('#alias').val();
    if(window.sessionStorage && sessionStorage['video_'+alias]){
        var videoinfo = sessionStorage['video_'+alias];
        $('#video_content').html('');
        $('#video_content').append(videoinfo);
        $('#dir1_container').hide();
        //设置所有预览图box高度等于宽度
        var video_witdh = $('#video_width').val();
        $('.video_box').css('width',video_witdh);
        $('.video_box').css('height',parseInt(video_witdh)+45);
        $('.video_box img').css('height',video_witdh);
        //记录动作
        sessionStorage[alias+'_action'] ="4%"+'video_'+alias;
        $('#video_container').show();
    }
    else if($.cookie('video_'+alias)){
        var videoinfo =$.cookie('video_'+alias);
        $('#view_content').html('');
        $('#view_content').append(videoinfo);
        //设置所有预览图box高度等于宽度
        var video_witdh = $('#video_width').val();
        $('.video_box').css('width',video_witdh);
        $('.video_box').css('height',parseInt(video_witdh)+45);
        $('.video_box img').css('height',video_witdh);
        $('#dir1_container').hide();
        $('#view_container').show();
    }else{
        //获取该企业视频信息
        $.ajax({
            type: "POST",
            url: mw_site_url+"/dir/ajax",
            async: true,
            data: "op=3&alias="+alias,
            dataType:"json",
            cache:false,
            beforeSend:function(){
                //隐藏一级目录，显示二级目录
                $('#video_content').html("<section class='loading'></section>");
                $('#dir1_container').hide();
                $('#video_container').show();
            },
            success:function(data){
                $('#video_content').find('.loading').remove();
                if(parseInt(data['error'])==1){
                    alert(data['error_msg']);
                }else{
                    var videoinfo = data['data'];
                    var video_html = "";
                    for(var i=0;i<videoinfo.length;i++){
                        $('#video_content').append(videoinfo[i]);
                        video_html+=videoinfo[i];
                    }
                    if(window.sessionStorage){
                        var alias = $('#alias').val();
                        sessionStorage['video_'+alias]=video_html;
                        //记录动作
                        sessionStorage[alias+'_action'] ="4%"+'video_'+alias;
                    }else{
                        $.cookie("video_"+alias,video_html);
                    }
                    //设置所有预览图box高度等于宽度
                    var video_witdh = $('#video_width').val();
                    $('.video_box').css('width',video_witdh);
                    $('.video_box').css('height',parseInt(video_witdh)+45);
                    $('.video_box img').css('height',video_witdh);
                }
            }
        });
    }
}

//点击企业视频head返回一级目录
function click_videohead(){
    $('#video_container').hide();
    $('#dir1_container').show();
    sessionStorage[alias+'_action'] ="1%sb";
}
